/*
 * 定义函数的方式
 * 
 */

/* ---------------------------	普通方式	------------------------- */

function square(x) {
	return x * x;
}
// alert(square(2));
/* ---------------------------	literal方式	------------------------- */

var square = function(x) {
	return x * x;
}
// alert(square(2));

/* ---------------------------	非常用方式	------------------------- */

var square = new Function("x", "return x*x;");
// alert(square(2));

var Person = {
	"name"			: "Homer Simpson",
	"age"			: 34,
	"married"		: true,
	"occupation"	: "plant operator",
	'email'			: "homer@example.com"
};

for (var p in Person) {
	Person[p] + ' : ' + p + ' ,\n ';
}

function makeProperty(o, name, predicate) {
	var value;
	o["get" + name] = function() {
		return value;
	};
	o["set" + name] = function(v) {
		if (predicate && !predicate(v))
			throw "set" + name + ": invalid value " + v;
		else
			value = v;
	};
}
var o = {};
makeProperty(o, "Name", function(x) {
			return typeof x == "string";
		});
o.setName("Frank");
alert(o.getName());
o.setName(0);

